<template>
    <div>
        <Form :model="formItem" inline>
            <FormItem>
                <Input v-model="formItem.company" placeholder="单位"></Input>
            </FormItem>
            <FormItem>
                <Input v-model="formItem.fuel" placeholder="油量"></Input>
            </FormItem>
            <FormItem>
                <Button type="success" @click="search">搜索</Button>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="exportData"><Icon type="ios-download-outline"></Icon>导出</Button>
            </FormItem>
            <FormItem>
                <Button type="info" @click="back()">返回</Button>
            </FormItem>
        </Form>
        <Table border :columns="columns12" :data="data6" ref="table" :loading="loading">
            <template slot-scope="{ row }" slot="fuel">
                <strong >{{ row.fuel }}</strong>
            </template>
        </Table>
    </div>
</template>

<script>
import { getExportSpvTransactionsByFuelList } from '@/api/user'
export default {
  data () {
    return {
      loading: true,
      formItem: {
        fuel: '',
        company: ''
      },
      modal2: false,
      value7: '',
      value: '',
      value1: '',
      value2: ['2016-01-01', '2016-02-15'],
      columns12: [
        {
          title: '交易流水号',
          key: 'batch_number',
          align: 'center'
        },
        {
          title: '金额',
          key: 'money',
          align: 'center'
        },
        {
          title: '油量',
          key: 'fuel',
          slot: 'fuel',
          align: 'center'
        },
        {
          title: '交易类型',
          key: 'transaction_type',
          align: 'center'
        },
        {
          title: '交易状态',
          key: 'transaction_status',
          align: 'center'
        },
        {
          title: '卡号/客户编号',
          key: 'card_num',
          align: 'center'
        },
        {
          title: '客户名称',
          key: 'name',
          align: 'center'
        },
        {
          title: '商品种类',
          key: 'type',
          align: 'center'
        },
        // {
        //   title: '多次加油的次数',
        //   key: 'count_num',
        //   align: 'center'
        // },
        {
          title: '受理机构',
          key: 'acceptance_organization',
          align: 'center'
        },
        {
          title: '业务日期',
          key: 'business_time',
          align: 'center'
        },
        {
          title: '交易时间',
          key: 'transaction_time',
          align: 'center'
        },
        // {
        //   title: '石油公司名称',
        //   key: 'oil_company_name',
        //   align: 'center'
        // },
        {
          title: '单位',
          key: 'company',
          align: 'center'
        },
        {
          title: '石油公司',
          key: 'oil_companies',
          align: 'center'
        },
        {
          title: '问题类型',
          key: 'problem',
          align: 'center'
        }
        // {
        //   title: '操作',
        //   slot: 'action',
        //   width: 100,
        //   align: 'center'
        // }
      ],
      data6: [],
      total: 0
    }
  },
  methods: {
    async init (data) {
      getExportSpvTransactionsByFuelList(data).then(ret => {
        this.data6 = ret.data.data
        this.data6.forEach(item => {
          item.problem = '超量加油'
        })
        this.loading = false
      })
    },
    search () {
      const data = {
        fuel: parseInt(this.formItem.fuel),
        company: this.formItem.company
      }
      this.init(data)
    },
    exportData () {
      for (let i = 0; i < this.data6.length; i++) {
        if (this.data6[i].batch_number) {
          this.data6[i].batch_number = '\t' + this.data6[i].batch_number
        }
        if (this.data6[i].card_num) {
          this.data6[i].card_num = '\t' + this.data6[i].card_num
        }
      }
      this.$refs.table.exportCsv({
        filename: '导出文件',
        columns: this.columns12,
        data: this.data6
      })
    },
    back () {
      this.$router.push({
        name: 'refueling-two'
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>
    .ivu-table .demo-table-info-cell-name {
        background-color: #2db7f5;
        color: #fff;
    }
</style>
